-
Notifications
You must be signed in to change notification settings - Fork 360
feat: add npm OIDC trusted publishing support #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add support for npm's OIDC trusted publishing, eliminating the need for long-lived NPM_TOKEN secrets. This provides better security through cryptographic provenance attestation and short-lived credentials. Changes: - Add `oidcAuth` boolean input parameter (default: false) - Implement OIDC environment validation: - Check npm version >= 11.5.1 - Verify id-token: write permission - Detect conflicting NPM_TOKEN - Early authentication validation before changeset operations - Skip .npmrc creation in OIDC mode (npm CLI auto-detects OIDC) - Explicit environment variable passing for compatibility with toolchains like proto shims and moon that start fresh shells - Maintain full backward compatibility with NPM_TOKEN authentication Tests: - 9 unit tests for OIDC validation - 13 integration tests for authentication setup - Full backward compatibility test coverage - All tests passing (30 total) Documentation: - Comprehensive OIDC setup guide with prerequisites - Migration instructions from NPM_TOKEN to OIDC - Clear explanation of benefits and provenance attestation - Example workflows for both authentication methods Resolves: changesets#515
|
|
I just landed #545 that chooses a simpler approach of conditionally messing with |
|
Hey @Andarist, thanks for reviewing and the feedback. Personally, I ran into some real-world issues when testing OIDC in production (at Adobe) that the simpler approach doesn't address, mostly around identifying why it was failing. If you wanted to help people avoid that, some validation would be nice. Without validation, users get cryptic npm errors instead of actionable feedback: With #545 (no validation): With validation (this PR): The first experience is frustrating - you don't know if it's a permission issue, npm version issue, or configuration issue. The second tells you exactly what's wrong and how to fix it. I ran into these 4 real issues that I had to debug and figure out (with many test pull requests) before finding the root issues:
If you don't think it's the role of the changesets action to validate, that totally makes sense as well. Another alternative would be to keep #545 as the default behavior, but add an opt-in If that doesn't seem to align with the project, I could consider splitting the validation functionality into a separate action for validation and debugging when needed. I'd be happy to adjust whatever you think is needed. |
|
Creating good error messages would be very nice. I probably think that ideally we'd handle this in |
|
@Andarist, even for things that are just GitHub action specific? |
Add npm OIDC Trusted Publishing Support
Overview
This PR adds support for npm's OIDC trusted publishing, eliminating the need for long-lived
NPM_TOKENsecrets. This provides enhanced security through cryptographic provenance attestation and short-lived credentials.Benefits
NPM_TOKENsecretsChanges
New Input Parameter
oidcAuthboolean input (default:false) to enable OIDC authenticationOIDC Validation
id-token: writepermission is granted in workflowNPM_TOKENconfigurationAuthentication Setup
.npmrccreation in OIDC mode (npm CLI auto-detects OIDC credentials)NPM_TOKENauthenticationEnvironment Variables Handling
ACTIONS_ID_TOKEN_REQUEST_URLandACTIONS_ID_TOKEN_REQUEST_TOKENare passed through to child processesTesting
.github/workflows/test-oidc-validation.yml)Documentation
Backward Compatibility
✅ Fully backward compatible - existing workflows using
NPM_TOKENcontinue to work without any changes.The
oidcAuthparameter defaults tofalse, so this is an opt-in feature.Example Usage
With OIDC (Recommended for New Projects)
Migration Path
For existing projects using
NPM_TOKEN:id-token: writepermissionoidcAuth: trueNPM_TOKENfrom workflow and GitHub secretsPrerequisites for OIDC
id-token: writepermissionAdditional Context
This implementation has been thoroughly tested in production:
Related Issues
Resolves #515 (if exists - npm OIDC support request)